package com.chinafree.permission.model.bo;


import com.chinafree.permission.model.dto.UserDTO;
import com.chinafree.permission.model.po.UserRolePO;
import lombok.*;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RoleDepartUserEditBO {

    private Integer roleId;
    private List<UserDTO> userList;

    public Optional<List<UserRolePO>> toUserRolePOList() {
        if (CollectionUtils.isEmpty(userList)) {
            return Optional.empty();
        }
        List<UserRolePO> userRolePOList = new ArrayList<>();
        for (UserDTO user : userList) {
            UserRolePO build = UserRolePO.builder()
                    .roleId(this.roleId)
                    .userId(user.getId()).build();
            userRolePOList.add(build);
        }
        if (CollectionUtils.isEmpty(userRolePOList)) {
            return Optional.empty();
        }
        return Optional.of(userRolePOList);
    }



}
